package com.yellowninja.backup.util;

import java.io.File;

import java.util.Date;

/**
 * The Backup object contains information about the backup to run.
 * 
 * @author Devin Gillman
 * 
 */
public class Backup {
	public static final int COMPLETE = 0;
	public static final int INCREMENTAL = 1;

	private String name, saveLocation, backupLocation;

	private Date lastRunDate;

	private int id, type, schedule;

	public Backup(int id, String name, String backupLocation,
			String saveLocation, Date lastRunDate, int type, int schedule) {
		this.id = id;
		this.lastRunDate = lastRunDate;
		this.backupLocation = backupLocation;
		this.name = name;
		this.saveLocation = saveLocation;
		this.type = type;
		this.schedule = schedule;
	}

	public Backup(String name, String backupLocation, String saveLocation,
			Date lastRunDate) {
		this(-1, name, backupLocation, saveLocation, lastRunDate, COMPLETE, 1);
	}

	public Backup(String name, String backupLocation, String saveLocation,
			int type, int schedule) {
		this(-1, name, backupLocation, saveLocation, null, type, schedule);
	}

	public Backup(String name, String backupLocation, String saveLocation,
			Date lastRunDate, int type, int schedule) {
		this(-1, name, backupLocation, saveLocation, lastRunDate, type,
				schedule);
	}

	public Backup(int id, String name, String backupLocation,
			String saveLocation, int type, int schedule) {
		this(id, name, backupLocation, saveLocation, null, type, schedule);
	}

	public int getID() {
		return id;
	}

	public void setID(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSaveLocation() {
		return saveLocation;
	}

	public void setSaveLocation(String saveLocation) {
		this.saveLocation = saveLocation;
	}

	public String getBackupLocation() {
		return backupLocation;
	}

	public void setBackupLocation(String backupLocation) {
		this.backupLocation = backupLocation;
	}

	public Date getLastRunDate() {
		return lastRunDate;
	}

	public void setLastRunDate(Date lastRunDate) {
		this.lastRunDate = lastRunDate;
	}

	public String getSavePath() {
		return saveLocation + File.separator + name;
	}

	public String getBackupFilePath() {
		return saveLocation + File.separator + name + File.separator + name
				+ ".xml";
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	/**
	 * @return the schedule
	 */
	public int getSchedule() {
		return schedule;
	}

	/**
	 * @param schedule
	 *            the schedule to set
	 */
	public void setSchedule(int schedule) {
		this.schedule = schedule;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof Backup))
			return false;
		Backup backup = (Backup) obj;

		return backup.getID() == id;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return name;
	}
}
